package json

import (
	"github.com/gin-gonic/gin"
	"net/http"
)

type Login struct {
	User     string `form:"username" json:"user" url:"user" xml:"user" binding:"required"`
	Password string `form:"password" json:"password" uri:"password" xml:"password" binding:"required"`
}

func init() {
	r := gin.Default()
	r.POST("login", func(context *gin.Context) {
		var json Login
		if err := context.ShouldBindJSON(&json); err != nil {
			context.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
			return
		}
		if json.User != "root" || json.Password != "admin" {
			context.JSON(http.StatusBadRequest, gin.H{
				"status":  "304",
				"message": "账号或密码错误",
			})
			return
		} else {
			context.String(http.StatusOK, "登录成功")
		}
	})

	r.Run(":8000")
}
